package main

import (
	"log"
	"fmt"
	"github.com/streadway/amqp"
	"time"
)

func isError(err error, msg string) {
	if err != nil{
		log.Fatal(fmt.Sprintf("%s: %s", msg, err))
		panic(fmt.Sprintf("%s:%s", msg, err))
	}
}

func main() {
	conn, err := amqp.Dial("amqp://localhost")
	isError(err, fmt.Sprintf("failed to connect"))

	ch, err := conn.Channel()
	isError(err, fmt.Sprintf("failed to create channel"))

	ch.ExchangeDeclare(
		"logs",
		"fanout",
		true,
		false,
		false,
		false,
		nil,
		)
	isError(err, "Failed to create exchange")


	err = ch.Publish(
			"logs",
			"",
			false,
			false,
			amqp.Publishing{
				DeliveryMode:amqp.Persistent,
				Body:[]byte("fuck"+time.Now().String()),
			})
	isError(err, "failed to publish message")

}